module.exports = {
  async fetch({ args,page }) {
    
    
    if (this.args.id=='chosen'){
    url = `http://baobab.kaiyanapp.com:80/api/v5/index/tab/feed?date=${page ||''}&num=2&udid=3162193e311b458697b79331330f12312d440426&vc=590&vn=6.2&size=1080X1920&deviceModel=FRD-AL10&first`
    } 
    else  if (this.args.id=='top')
    {url= `http://baobab.kaiyanapp.com:80/api/v4/rankList/videos?strategy=weekly&udid=3162193e311b458697b79331330f12312d440426&vc=590&vn=6.2&size=1080X1920&deviceModel=FRD-AL10&first_channel=eyepetizer_yingyongbao_market&last_channel=eyepetizer_yingyongbao_market&system_version_code=26`
    }
    else
    {url=`http://baobab.kaiyanapp.com:80/api/v3/lightTopics/internal/${this.args.id}?udid=3162193e311b458697b79331330f12312d440426&vc=590&vn=6.2&size=1080X1920&deviceModel=FRD-AL10&first_channel=eyepetizer_yingyongbao_market&last_channel=eyepetizer_yingyongbao_market&system_version_code=26`}
    let resp = await $http.get(url)
    
    
    if (this.args.id=='chosen')
    {
    let nextP = resp.data.nextPageUrl
    date=nextP.match('date=(.*?)&num')[1]
   }
   else 
   {date=null}
   console.log(date)
   
    let list = resp.data.itemList
    let items = list.map(data => {
      if (data.type == 'followCard'||data.type=='video'||data.type=='autoPlayFollowCard') {
        let data1=data.data.content.data
       return {
          title: data.data.header.title||data1.title,
          style: 'live',
          thumb:data1.cover.feed,
          spanCount: 12,
          label: data1.category,
          viewerCount: data1.consumption.collectionCount,
          author: {
            name: data1.author.name,
            avatar: data1.author.icon
          },
          route: $route('player', {
            id: data.data.header.id
          })
        }
      } 
      
      else if(data.type=='textCard'&data.data.text!='每日资讯精选') 
      {
        return {
          style: 'list',
          title: data.data.text
        }
      }
   
   
    })

    return {
      nextPage: date,
      items: items
    }
  }
}
